package com.softline.documentsmall.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.softline.documentsmall.dao.DictionaryKeywordConfigMapper;
import com.softline.documentsmall.dao.DictionaryMapper;
import com.softline.documentsmall.entity.Dictionary;
import com.softline.documentsmall.entity.DictionaryKeywordConfig;
import com.softline.documentsmall.entity.IsProfessionalTermVo;
import com.softline.documentsmall.service.DictionaryKeywordConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class DictionaryKeywordConfigServiceImpl extends ServiceImpl<DictionaryKeywordConfigMapper, DictionaryKeywordConfig> implements DictionaryKeywordConfigService {
    @Autowired
    DictionaryMapper dictionaryMapper;
    @Autowired
    DictionaryKeywordConfigMapper mapper;

    @Override
    public List<DictionaryKeywordConfig> searchListByParams(Long id, Integer dictionaryId, String keyword, Integer pageNo, Integer pageSize) {
        return baseMapper.searchListByParams(id,dictionaryId,keyword,(pageNo-1)*pageSize,pageSize);
    }

    @Override
    public Long getTotalCount(Long id, Integer dictionaryId, String keyword) {
       return baseMapper.getTotalCount(id,dictionaryId,keyword);
    }

    @Override
    public void dictionaryKeywordUpdate() {
        int success = 0;
        int fail = 0;
        int end = dictionaryMapper.findMaxId();
        for(int i=0;i<(end/100)+1;i++) {
            List<Dictionary> dictionaryList = dictionaryMapper.find(100*i,100);
            for(Dictionary list:dictionaryList){
                List<DictionaryKeywordConfig> list1 = mapper.searchListByKeyword(list.getNameEn());
                if(list1.size()==0){
                    mapper.keywordUpdate(list.getId(),list.getNameEn());
                    success++;
                } else {
                    fail++;
                }
                List<DictionaryKeywordConfig> list2 = mapper.searchListByKeyword(list.getNameCn());
                if(list2.size()==0) {
                    mapper.keywordUpdate(list.getId(), list.getNameCn());
                    success++;
                } else {
                    fail++;
                }
                List<DictionaryKeywordConfig> list3 = mapper.searchListByKeyword(list.getNameAr());
                if(list3.size()==0) {
                    mapper.keywordUpdate(list.getId(),list.getNameAr());
                    success++;
                } else {
                    fail++;
                }
                List<DictionaryKeywordConfig> list4 = mapper.searchListByKeyword(list.getNameDe());
                if(list4.size()==0) {
                    mapper.keywordUpdate(list.getId(),list.getNameDe());
                    success++;
                } else {
                    fail++;
                }
                List<DictionaryKeywordConfig> list5 = mapper.searchListByKeyword(list.getNameEs());
                if(list5.size()==0) {
                    mapper.keywordUpdate(list.getId(),list.getNameEs());
                    success++;
                } else {
                    fail++;
                }
                List<DictionaryKeywordConfig> list6 = mapper.searchListByKeyword(list.getNameFr());
                if(list6.size()==0) {
                    mapper.keywordUpdate(list.getId(),list.getNameFr());
                    success++;
                } else {
                    fail++;
                }
                List<DictionaryKeywordConfig> list7 = mapper.searchListByKeyword(list.getNameIt());
                if(list7.size()==0) {
                    mapper.keywordUpdate(list.getId(),list.getNameIt());
                    success++;
                } else {
                    fail++;
                }
                List<DictionaryKeywordConfig> list8 = mapper.searchListByKeyword(list.getNameJp());
                if(list8.size()==0) {
                    mapper.keywordUpdate(list.getId(),list.getNameJp());
                    success++;
                } else {
                    fail++;
                }
                List<DictionaryKeywordConfig> list9 = mapper.searchListByKeyword(list.getNameKr());
                if(list9.size()==0) {
                    mapper.keywordUpdate(list.getId(),list.getNameKr());
                    success++;
                } else {
                    fail++;
                }
                List<DictionaryKeywordConfig> list10 = mapper.searchListByKeyword(list.getNamePt());
                if(list10.size()==0) {
                    mapper.keywordUpdate(list.getId(),list.getNamePt());
                    success++;
                } else {
                    fail++;
                }
                List<DictionaryKeywordConfig> list11 = mapper.searchListByKeyword(list.getNameRu());
                if(list11.size()==0) {
                    mapper.keywordUpdate(list.getId(),list.getNameRu());
                    success++;
                } else {
                    fail++;
                }
            }
        }
        System.out.println("成功插入"+success+"条数据,失败"+fail+"条。");
    }


}
